#include "event.h"
#include "eventtransfer.h"

EventTransfer::EventTransfer()
{

}

EventTransfer::~EventTransfer()
{

}

void EventTransfer::postEvent(const EventPtr &ev)
{
    Mutex::scoped_lock lock(m_lock);

    m_eventQueue.push_back(ev);

    m_condition.notify_one();
}

void EventTransfer::peekEvent(EventPtr &ev)
{
    Mutex::scoped_lock lock(m_lock);

    while(m_eventQueue.empty()){
        m_condition.wait(m_lock);
    }

    ev = m_eventQueue.front();
    m_eventQueue.pop_front();
}

size_t EventTransfer::eventCount()
{
    Mutex::scoped_lock lock(m_lock);

    return m_eventQueue.size();
}
